/**
 * Created by lobin on 2017/7/24.
 */
import { Application } from 'egg';

export default (app: Application) => {
  const mongoose = app.mongoose;
  const schema = new mongoose.Schema({
    ctime: {
      type: Date,
      default: Date.now,
      required: true,
    },
    type: {
      type: String,
      required: true,
      default: 'express',
    },
    name: {
      type: String,
      required: true,
      unique: true,
    },
    tel: {
      type: String,
      max: 11,
      min: 11,
      required: false,
    },
    unionId: {
      type: String,
      required: true,
    },
    user: {
      type: String,
      required: true,
    },
    province: {
      type: String,
      required: true,
    },
    city: {
      type: String,
      required: true,
    },
    county: {
      type: String,
      required: true,
    },
    detail: {
      type: String,
      required: true,
    },
    is_default: {
      type: Boolean,
      required: true,
      default: false,
    },
    status: {
      type: String,
      default: 0, // 默认为0,1为暂停使用,3为删除
    },
  });
  schema.index({
    unionId: 1,
    ctime: -1,
    name: 1,
    site: 1,
    status: 1,
  });
  return mongoose.model('addressbook', schema, 'address_book');
};
